def handle_ability_name():
    path = "E:/IdeaProjects/jzjh3/jzjh3/table/"
    with open(file=path + "ability.ini", mode="r", encoding="utf-8") as f, open(file=path + "out.ini", mode="w",
                                                                                encoding="utf-8") as g:
        current_key = ""
        for line in f.readlines():
            print(line, end="")
            if line.startswith("["):
                current_key = line[1:5]
            if line.startswith("_parent"):
                words = line.split("\"")
                current_parent = words[1]
                if current_parent != current_key \
                        and not current_key.startswith("A0") \
                        and not current_key.startswith("A1"):
                    g.write('_parent = "{0}"\n'.format(current_key))
                    continue
            g.write(line)


if __name__ == '__main__':
    handle_ability_name()
